#include<iostream>
#include<bitset>
#include<algorithm>
using namespace std;
#define N 2510
int n,a[N][N],cnt;
bitset<N> b[N];
struct node
{
int w,x,y;
friend bool operator<(node a,node b)
{
return a.w>b.w;
}
}f[N*N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
f[++cnt]=(node){a[i][j],i,j};
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(a[i][j]!=a[j][i])
{
puts("NOT MAGIC");
return 0;
}
if(i==j&&a[i][j])
{
puts("NOT MAGIC");
return 0;
}
}
sort(f+1,f+cnt+1);
int now=0;
while(now<cnt)
{
now++;
int tmp=now;
b[f[now].x].set(f[now].y);
while(now<cnt&&f[now+1].w==f[now].w)
{
now++;
b[f[now].x].set(f[now].y);
}
if(now==cnt)
break;
for(int i=tmp;i<=now;i++)
{
int x=f[i].x,y=f[i].y;
if((b[x]|b[y]).count()!=n)
{
// cout<<x<<" "<<y<<":"<<(b[x]|b[y]).count()<<endl;
puts("NOT MAGIC");
return 0;
}
}
}
puts("MAGIC");
}
80A - Panoramix's Prediction | 1354B - Ternary String |
122B - Lucky Substring | 266B - Queue at the School |
1490A - Dense Array | 1650B - DIV + MOD |
1549B - Gregor and the Pawn Game | 553A - Kyoya and Colored Balls |
1364A - XXXXX | 1499B - Binary Removals |
1569C - Jury Meeting | 108A - Palindromic Times |
46A - Ball Game | 114A - Cifera |
776A - A Serial Killer | 25B - Phone numbers |
1633C - Kill the Monster | 1611A - Make Even |
1030B - Vasya and Cornfield | 1631A - Min Max Swap |
1296B - Food Buying | 133A - HQ9+ |
1650D - Twist the Permutation | 1209A - Paint the Numbers |
1234A - Equalize Prices Again | 1613A - Long Comparison |
1624B - Make AP | 660B - Seating On Bus |
405A - Gravity Flip | 499B - Lecture |